#!/bin/bash

MIRROR_ALI=registry.cn-hangzhou.aliyuncs.com

PROFILE=$1
SERVICE_NAME=$2
SERVICE_VERSION=$3
SERVICE=$SERVICE_NAME:$SERVICE_VERSION

echo "build profile:$PROFILE for service:$SERVICE"

# 准备maven仓库缓存
docker volume create --name tmp

docker run \
    --user $(id -u):$(id -g) \
    -v $(pwd):/app -v tmp:/tmp -w /app \
    -e _JAVA_OPTIONS=-Duser.home=/tmp \
    maven:3-jdk-8 \
    mvn -s support/mvn/settings.xml package -P$PROFILE

docker build -t $MIRROR_ALI/westeros/$SERVICE .
docker push $MIRROR_ALI/westeros/$SERVICE
